﻿using Advantech.Motion;
using EquipSecs300;
using Newtonsoft.Json;
using RRQMSocket;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using VisionCore;
using DLLPC.Utilities;

namespace VisionCore.SECS
{
    public class SecsEQFunc
    {
        private static bool isRun = true;
        private static Thread thread;
        private static bool Door_LockBuf;
        private static bool foupStstesPABuf;
        private static bool foupStstesPBBuf;
        private static bool[] EQStates = new bool[20];
        private static bool[] EQStatesBuf = new bool[20];
        private static byte[] PortStates = new byte[10];
        private static byte[] PortStatesBuf = new byte[10];
        private static bool[] PortPresentStates = new bool[2];
        private static bool[] PortPresentStatesBuf = new bool[2];
        private static SystemTimeCounter scStatus = new SystemTimeCounter();
        private static bool IsTime;

        public static SePresentData SePresentData_PA { get; set; }
        public static SePresentData SePresentData_PB { get; set; }

        public static void Start(SecsEquipHelper secsEquip)
        {
            AttachEvent(secsEquip);
            SecsGlobalVar.InitalSetting(secsEquip);

            thread = new Thread(threadFunction);
            thread.IsBackground = true;
            thread.Start();
            scStatus.Start();
        }
        public static void Quit()
        {
            isRun = false;
        }

        private static void threadFunction()
        {
            while (isRun/* && ParameterHelper.SysParam.EQ.SECSEnable*/)
            {
                if (scStatus.Duration > 10000 || IsTime)
                {
                    FreshStatus();
                    IsTime = true;
                }

                SystemTimeCounter.timeBeginPeriod(1);
                Thread.Sleep(1);
                SystemTimeCounter.timeEndPeriod(1);

            }
        }

        public static void AttachEvent(SecsEquipHelper secsEquip)
        {
            secsEquip.AcLogMsg += SeLogMsg;
            secsEquip.Alarm.AcLogMsg += SeLogMsg;
            secsEquip.Even.AcLogMsg += SeLogMsg;
            secsEquip.Variables.AcLogMsg += SeLogMsg;
            secsEquip.RemoteContro.AcLogMsg += SeLogMsg;
            secsEquip.Recipe.AcLogMsg += SeLogMsg;
            secsEquip.PPFormat.AcLogMsg += SeLogMsg;
            secsEquip.Constant.AcLogMsg += SeLogMsg;
            secsEquip.PPCostomize.AcLogMsg += SeLogMsg;
            secsEquip.PJob.AcLogMsg += SeLogMsg;
            secsEquip.CJob.AcLogMsg += SeLogMsg;
            secsEquip.LoadPort.AcLogMsg += SeLogMsg;
            secsEquip.LoadPort.MapPort["Port_1"].AcLogMsg += SeLogMsg;
            secsEquip.LoadPort.MapPort["Port_2"].AcLogMsg += SeLogMsg;
            secsEquip.SubstrateTracking.AcLogMsg += SeLogMsg;

            secsEquip.RemoteContro.SeGetWaferIDList += GetWafersID;
        }

        private static void StatesAdd()//SECS
        {
            //EQStates[0] = Kernel.EQ.GlobalVars.ManualMode;
            //EQStates[1] = VisionCore.EQ.GlobalVars.AutoMode;
            //EQStates[2] = VisionCore.EQ.GlobalVars.InitMode;
            //EQStates[3] = VisionCore.EQ.GlobalVars.PauseMode;
            //EQStates[4] = VisionCore.EQ.GlobalVars.StepStop;
         
            //EQStates[8] = VisionCore.Insp.GlobalVars.InspStart;
          
            //if (!VisionCore.EQ.GlobalVars.InitMode)
            //{
            //    EQStates[12] = VisionCore.EQ.GlobalVars.Alarm;
            //}
            //EQStates[13] = VisionCore.EQ.GlobalVars.Warning;



            //PortStates[0] = (byte)VisionCore.Efem.Port.GlobalVars.PASize;
            //PortStates[1] = Kernel.Efem.Port.LPA.IO.FOUPClampStatus;
            //PortStates[2] = Kernel.Efem.Port.LPA.IO.DoorPosition;
            //PortStates[3] = Kernel.Efem.Port.LPA.IO.Y_aixsPosition;

            //PortStates[5] = (byte)VisionCore.Efem.Port.GlobalVars.PBSize;
            //PortStates[6] = Kernel.Efem.Port.LPB.IO.FOUPClampStatus;
            //PortStates[7] = Kernel.Efem.Port.LPB.IO.DoorPosition;
            //PortStates[8] = Kernel.Efem.Port.LPB.IO.Y_aixsPosition;


            PortPresentStates[0] = ParameterHelper.PortA.Enable;
            PortPresentStates[1] = ParameterHelper.PortB.Enable;
        }
        private static bool EQStatesComp()//SECS
        {
            for (int i = 0; i < EQStates.Length; i++)
            {
                if (EQStates[i] != EQStatesBuf[i])
                {
                    return true;
                }
            }
            return false;
        }
        private static bool PortStatesComp()
        {
            for (int i = 0; i < PortStates.Length; i++)
            {
                if (PortStates[i] != PortStatesBuf[i])
                {
                    return true;
                }
            }
            return false;
        }
        private static bool PortPresentComp()
        {
            for (int i = 0; i < PortPresentStates.Length; i++)
            {
                if (PortPresentStates[i] != PortPresentStatesBuf[i])
                {
                    for (int j = 0; j < PortPresentStates.Length; j++)
                    {
                        PortPresentStatesBuf[j] = PortPresentStates[j];
                    }
                    return true;
                }
            }
            return false;
        }
        private static bool IsIdle()
        {
            //for (int i = 0; i < 25; i++)
            //{
            //    if (ParameterHelper.PortA.Enable && ParameterHelper.PortA.MapDatas[i].Sel)
            //    {
            //        if (!ParameterHelper.PortA.MapDatas[i].Inspected)
            //        {
            //            return false;
            //        }
            //    }
            //    if (ParameterHelper.PortB.Enable && ParameterHelper.PortB.MapDatas[i].Sel)
            //    {
            //        if (!ParameterHelper.PortB.MapDatas[i].Inspected)
            //        {
            //            return false;
            //        }
            //    }
            //}
            if (ParameterHelper.LaserST1.Enable || ParameterHelper.Aligner.Enable || ParameterHelper.RBUpper.Enable || ParameterHelper.RBLower.Enable || ParameterHelper.PortA.Enable || ParameterHelper.PortB.Enable )
            {
                return false;
            }
            return true;

        }

        static bool portAStateValueChange = false;
        static bool portBStateValueChange = false;
        static bool portAStateValueChange1 = false;
        static bool portBStateValueChange1 = false;
        static bool LPAConnectedBuf = false;
        static bool LPBConnectedBuf = false;
        private static void FreshStatus()
        {

            #region  机台状态报告
            StatesAdd();
            if (EQStatesComp())//SECS
            {
                for (int i = 0; i < EQStates.Length; i++)
                {
                    EQStatesBuf[i] = EQStates[i];
                }

#if false  //暂时pass  20250526

                if (ProcedureHelper_EQ.ManualMode)
                {
                    if (VisionCore.EQ.GlobalVars.Alarm)
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.MANUAL, DeviceStatus_KE.ALARM);
                        LogHelper.Write(LogHelper.Module.Process, "1_设备状态切换: MANUAL-ALARM");
                    }
                    else
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.MANUAL, DeviceStatus_KE.STOP);
                        LogHelper.Write(LogHelper.Module.Process, "2_设备状态切换: MANUAL-STOP");
                    }

                }
                else if (VisionCore.EQ.GlobalVars.AutoMode)
                {
                    if (VisionCore.EQ.GlobalVars.Alarm)
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.AUTO, DeviceStatus_KE.ALARM);
                        LogHelper.Write(LogHelper.Module.Process, "3_设备状态切换: AUTO-ALARM");
                    }
                    //else if (VisionCore.EQ.GlobalVars.InitMode)
                    //{
                    //    Kernel.SecsEquip.Even.Ev_EQ_States_Change(DeviceMode_KE.AUTO, DeviceStatus_KE.HOMING);
                    //}
                    else if (VisionCore.Insp.GlobalVars.InspStart && IsIdle())
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.AUTO, DeviceStatus_KE.IDLE);
                        LogHelper.Write(LogHelper.Module.Process, "4_设备状态切换: AUTO-IDLE");
                    }
                    else if (VisionCore.Insp.GlobalVars.InspStart)
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.AUTO, DeviceStatus_KE.AUTO_RUN);
                        LogHelper.Write(LogHelper.Module.Process, "5_设备状态切换: AUTO-AUTO_RUN");
                    }
                    else
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.AUTO, DeviceStatus_KE.STOP);
                        LogHelper.Write(LogHelper.Module.Process, "7_设备状态切换: AUTO-STOP");
                    }
                }
                else if (VisionCore.EQ.GlobalVars.StepStop)
                {
                    if (VisionCore.EQ.GlobalVars.Alarm)
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.AUTO, DeviceStatus_KE.ALARM);
                        LogHelper.Write(LogHelper.Module.Process, "8_设备状态切换: AUTO-ALARM");
                    }
                    else if (VisionCore.Insp.GlobalVars.InspStart)
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.AUTO, DeviceStatus_KE.STOP);
                        LogHelper.Write(LogHelper.Module.Process, "9_设备状态切换: AUTO-STOP");
                    }
                    else
                    {
                        Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.AUTO, DeviceStatus_KE.STANDBY);
                        LogHelper.Write(LogHelper.Module.Process, "10_设备状态切换: AUTO-STANDBY");
                    }
                }
                else if (VisionCore.EQ.GlobalVars.InitMode)
                {
                    //if (VisionCore.EQ.GlobalVars.Alarm)
                    //{
                    //    Kernel.SecsEquip.Even.Ev_EQ_States_Change(DeviceMode_KE.AUTO, DeviceStatus_KE.ALARM);
                    //}

                    Kernel.SecsEquip.Even.Ev_EQStatesChange(DeviceMode_KE.AUTO, DeviceStatus_KE.HOMING);
                    LogHelper.Write(LogHelper.Module.Process, "10_设备状态切换: AUTO-HOMING");

                }

#endif
                string strStates = "";
                for (int i = 0; i < EQStates.Length; i++)
                {
                    strStates += EQStates[i] ? "1" : "0";
                }
                //LogHelper.Write(LogHelper.Module.Process, strStates);

#region 切手动Port状态刷新
                if (ProcedureHelper_EQ.ManualMode)
                {
                    portAStateValueChange = false;
                    portAStateValueChange1 = false;
                    portBStateValueChange = false;
                    portBStateValueChange1 = false;
                    LPAConnectedBuf = false;
                    LPBConnectedBuf = false;
                }
#endregion
            }
#endregion

#region 安全门状态自动报告
            if (Door_LockBuf != ProcedureHelper_EQ.Door_Lock) //SECS
            {
                Door_LockBuf = ProcedureHelper_EQ.Door_Lock;
                if (ProcedureHelper_EQ.Door_Lock)
                {
                    Kernel.SecsEquip.Even.Ev_EQDoorStates(EfemEqSafetyDoorStatus_KE.LOCKED, InspEqSafetyDoorStatus_KE.LOCKED);
                }
                else
                {
                    Kernel.SecsEquip.Even.Ev_EQDoorStates(EfemEqSafetyDoorStatus_KE.UNLOCKED, InspEqSafetyDoorStatus_KE.UNLOCKED);
                }

            }
            #endregion

            #region Port Foup状态变化

            //PortFoupStageReport(VisionCore.Efem.Port.GlobalVars.PASize, PortNO_KE.Port1, ParameterHelper.PortA, Kernel.Efem.Port.LPA);
            //PortFoupStageReport(VisionCore.Efem.Port.GlobalVars.PBSize, PortNO_KE.Port2, ParameterHelper.PortB, Kernel.Efem.Port.LPB);


            //无EFEM
            //if (true || ProcedureHelper_EQ.ManualMode)
            //{
            //    if (((VisionCore.Efem.Port.GlobalVars.PASize == WaferSize.Inch_8) || (VisionCore.Efem.Port.GlobalVars.PASize == WaferSize.Inch_12)) && !portAStateValueChange)
            //    {
            //        Kernel.SecsEquip.Variables.SetValue(10190, "1");
            //        portAStateValueChange = true;
            //        portAStateValueChange1 = false;
            //    }
            //    if (VisionCore.Efem.Port.GlobalVars.PASize == WaferSize.Sparce && !portAStateValueChange1)
            //    {
            //        Kernel.SecsEquip.Variables.SetValue(10190, "0");
            //        portAStateValueChange = false;
            //        portAStateValueChange1 = true;
            //    }
            //    if (((VisionCore.Efem.Port.GlobalVars.PBSize == WaferSize.Inch_8) || (VisionCore.Efem.Port.GlobalVars.PBSize == WaferSize.Inch_12)) && !portBStateValueChange)
            //    {
            //        Kernel.SecsEquip.Variables.SetValue(10191, "1");
            //        portBStateValueChange = true;
            //        portBStateValueChange1 = false;
            //    }
            //    if (VisionCore.Efem.Port.GlobalVars.PBSize == WaferSize.Sparce && !portBStateValueChange1)
            //    {
            //        Kernel.SecsEquip.Variables.SetValue(10191, "0");
            //        portBStateValueChange = false;
            //        portBStateValueChange1 = true;
            //    }


            //    if (Kernel.Efem.Port.LPA != null && Kernel.Efem.Port.LPA != null)
            //    {
            //        if (Kernel.Efem.Port.LPA.Connected != LPAConnectedBuf)
            //        {
            //            LPAConnectedBuf = Kernel.Efem.Port.LPA.Connected;

            //            if (!Kernel.Efem.Port.LPA.Connected)
            //            {
            //                Kernel.SecsEquip.Variables.SetValue(10190, "60");
            //            }
            //        }
            //        if (Kernel.Efem.Port.LPA.Connected != LPBConnectedBuf)
            //        {
            //            LPBConnectedBuf = Kernel.Efem.Port.LPB.Connected;

            //            if (!Kernel.Efem.Port.LPB.Connected)
            //            {
            //                Kernel.SecsEquip.Variables.SetValue(10191, "60");
            //            }
            //        }
            //    }


            //}


            #endregion

            #region 上抛用在席资料自动赋值
            //
            //不在这边赋值项目 ： WAFER_ST , WFRESULT , SeInspCommonItem.CHECK_POINT_X_POS , SeInspCommonItem.CHECK_POINT_Y_POS 
            //



            //暂时pass  20250526
            //ParameterHelper.RotateST.SePresentData.WAFERID = StrReplase(ParameterHelper.RotateST.Wafer_ID);
            //ParameterHelper.RotateST.SePresentData.PORTNO = (short)((int)ParameterHelper.RotateST.CST.Pos + 1);
            //ParameterHelper.RotateST.SePresentData.SLOTNO = (short)ParameterHelper.RotateST.CST.Slot;
            //ParameterHelper.RotateST.SePresentData.SeInspCommonItem.INTIME = ParameterHelper.RotateST.StartDT.ToString("yyyyMMddHHmmss");
            //ParameterHelper.RotateST.SePresentData.SeInspCommonItem.OUTTIME = ParameterHelper.RotateST.EndDT.ToString("yyyyMMddHHmmss");
            //ParameterHelper.RotateST.SePresentData.SeInspCommonItem.PPID = ParameterHelper.CurParam.PRM_Name;
            //ParameterHelper.RotateST.SePresentData.SeInspCommonItem.PortFoupID = ParameterHelper.RotateST.CST.RFID;
            //ParameterHelper.RotateST.SePresentData.WAFERID_Lot = ParameterHelper.RotateST.Wafer_ID_Lot;

            //ParameterHelper.Aligner.SePresentData.WAFERID = StrReplase(ParameterHelper.Aligner.Wafer_ID);
            //ParameterHelper.Aligner.SePresentData.PORTNO = (short)((int)ParameterHelper.Aligner.CST.Pos + 1);
            //ParameterHelper.Aligner.SePresentData.SLOTNO = (short)ParameterHelper.Aligner.CST.Slot;
            //ParameterHelper.Aligner.SePresentData.SeInspCommonItem.INTIME = ParameterHelper.Aligner.StartDT.ToString("yyyyMMddHHmmss");
            //ParameterHelper.Aligner.SePresentData.SeInspCommonItem.OUTTIME = ParameterHelper.Aligner.EndDT.ToString("yyyyMMddHHmmss");
            //ParameterHelper.Aligner.SePresentData.SeInspCommonItem.PPID = ParameterHelper.CurParam.PRM_Name;
            //ParameterHelper.Aligner.SePresentData.SeInspCommonItem.PortFoupID = ParameterHelper.Aligner.CST.RFID;
            //ParameterHelper.Aligner.SePresentData.WAFERID_Lot = ParameterHelper.Aligner.Wafer_ID_Lot;

            //ParameterHelper.InspST.SePresentData.WAFERID = StrReplase(ParameterHelper.InspST.Wafer_ID);
            //ParameterHelper.InspST.SePresentData.PORTNO = (short)((int)ParameterHelper.InspST.CST.Pos + 1);
            //ParameterHelper.InspST.SePresentData.SLOTNO = (short)ParameterHelper.InspST.CST.Slot;
            //ParameterHelper.InspST.SePresentData.SeInspCommonItem.INTIME = ParameterHelper.InspST.StartDT.ToString("yyyyMMddHHmmss");
            //ParameterHelper.InspST.SePresentData.SeInspCommonItem.OUTTIME = ParameterHelper.InspST.EndDT.ToString("yyyyMMddHHmmss");
            //ParameterHelper.InspST.SePresentData.SeInspCommonItem.PPID = ParameterHelper.CurParam.PRM_Name;
            //ParameterHelper.InspST.SePresentData.SeInspCommonItem.PortFoupID = ParameterHelper.InspST.CST.RFID;
            //ParameterHelper.InspST.SePresentData.WAFERID_Lot = ParameterHelper.InspST.Wafer_ID_Lot;


            #endregion

            #region 标志清除


            //暂时pass  20250526

            //if (!Kernel.PRS.Efem.PA.Presence/*PA_Empty*/)
            //{

            //    EquipSecs300.GlobalVar.StartScan["Port_1"] = false;
            //    VisionCore.Efem.Port.GlobalVars.PABlock = false;
            //    if (!(ParameterHelper.PortA == null))
            //    {
            //        ParameterHelper.PortA.SeEvenState.PortBlocked = false;
            //    }

            //}
            //if (!Kernel.PRS.Efem.PB.Presence/*PB_Empty*/)
            //{
            //    EquipSecs300.GlobalVar.StartScan["Port_2"] = false;
            //    VisionCore.Efem.Port.GlobalVars.PBBlock = false;
            //    if (!(ParameterHelper.PortB == null))
            //    {
            //        ParameterHelper.PortB.SeEvenState.PortBlocked = false;
            //    }

            //}
            #endregion

            #region 删除CJob和PJob
            if (PortPresentComp())
            {
                if (!ParameterHelper.PortA.Enable && !ParameterHelper.PortB.Enable)
                {
                    Kernel.SecsEquip.CJob.JobDeleteAllForce();
                    Kernel.SecsEquip.PJob.JobDeleteAllForce();
                }
            }
#endregion
        }

        static string StrReplase(string strCur)
        {
            if(string.IsNullOrEmpty(strCur)) return strCur;
            string strNewWafer_ID = "";
            if (SecsDataHelper.Function.IsWaferIDCanContain_)
            {
                strNewWafer_ID = strCur;
            }
            else
            {
                strNewWafer_ID = strCur.Replace("-", "#");
            }
            return strNewWafer_ID;
        }

        static string strPortNO;

        ////暂时pass  20250526
        //        static void PortFoupStageReport(WaferSize portWaferSize, PortNO_KE portNO, PortInfo portInfo, IPortHelper portHelper)
        //        {
        //            if (portNO == PortNO_KE.Port1)
        //            {
        //                strPortNO = "Port_1";
        //            }
        //            else
        //            {
        //                strPortNO = "Port_2";
        //            }
        //            if (true)
        //            {
        //                if (portWaferSize == WaferSize.Sparce)
        //                {
        //#region
        //                    Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_LoadPortUnloadReady_R();
        //                    if (portInfo.SeEvenState.LoadPortLoaded && !SecsGlobalVar.LoadPortReadUnLoad[strPortNO])//金南瓜SKD调Ev_LoadPortUnLoaded前需要先调用Ev_LoadPortUnloadReady，不然会有问题。
        //                    {
        //                        Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_LoadPortUnloadReady(PortFoupStatus_KE.CarrierClosed, portInfo.RFID);
        //                        SecsGlobalVar.LoadPortReadUnLoad[strPortNO] = true;
        //                    }
        //                    Thread.Sleep(200);
        //#endregion

        //                    Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_LoadPortLoaded_R();
        //                    Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_LoadPortUnLoaded(PortFoupStatus_KE.UnLoaded, portInfo.RFID);
        //                    //Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_PORT_READY_LOAD(portInfo.PortFoupStatus, portInfo.RFID);
        //                }
        //                else if (((portWaferSize == WaferSize.Inch_8) || (portWaferSize == WaferSize.Inch_12)))
        //                {
        //#region
        //                    portInfo.SeEvenState.LoadPortLoaded = true;
        //                    SecsGlobalVar.LoadPortReadUnLoad[strPortNO] = false;
        //#endregion

        //                    Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_LoadPortUnLoaded_R();
        //                    Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_LoadPortLoaded(PortFoupStatus_KE.Loaded, portInfo.RFID);
        //                    //Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_PORT_READY_LOAD_R();
        //                }
        //                if (true)//临时屏蔽
        //                {
        //                    if (SecsDataHelper.Function.LoadPortAdapWhole)
        //                    {
        //                        if (portHelper.IO.FOUPClampStatus == 1 && portInfo.Enable)
        //                        {
        //                            Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_BoxCarrierUnClamped_R();
        //                            Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_BoxCarrierClamped(PortFoupStatus_KE.Clamp, portInfo.RFID);
        //                        }
        //                        else if (portHelper.IO.FOUPClampStatus == 0 && portInfo.Enable)
        //                        {
        //                            Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_BoxCarrierClamped_R();
        //                            Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_BoxCarrierUnClamped(PortFoupStatus_KE.UnClamp, portInfo.RFID);
        //                        }

        //                        if (portHelper.IO.DoorPosition == 0 && portInfo.Enable)
        //                        {
        //                            Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_BoxCarrierClosed_R();
        //                            Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_BoxCarrierOpened(PortFoupStatus_KE.CarrierOpened, portInfo.RFID);
        //                        }
        //                        else if (portHelper.IO.DoorPosition == 1 && portInfo.Enable)
        //                        {
        //                            Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_BoxCarrierOpened_R();
        //                            Kernel.SecsEquip.LoadPort.MapPort[strPortNO].Ev_BoxCarrierClosed(PortFoupStatus_KE.CarrierClosed, portInfo.RFID);
        //                        }
        //                    }
        //                }


        //            }

        //#region 手动状态Foup状态变化报告
        //            if (true)
        //            {
        //                if (VisionCore.EQ.GlobalVars.ManualMode)
        //                {
        //                    if (PortStatesComp())
        //                    {
        //                        if (portNO == PortNO_KE.Port1)
        //                        {
        //                            for (int i = 0; i < 5; i++)
        //                            {
        //                                PortStatesBuf[i] = PortStates[i];
        //                            }
        //                        }
        //                        else
        //                        {
        //                            for (int i = 0; i < PortStates.Length; i++)
        //                            {
        //                                PortStatesBuf[i] = PortStates[i];
        //                            }
        //                        }

        //                        if (!((portInfo.Size == WaferSize.Inch_8 && portWaferSize == WaferSize.Inch_8) || (portInfo.Size == WaferSize.Inch_12 && portWaferSize == WaferSize.Inch_12)))
        //                        {
        //                            Kernel.SecsEquip.Even.Ev_PortFoupStates(portNO, portInfo.PortFoupStatus);
        //                        }
        //                        else if (((portInfo.Size == WaferSize.Inch_8 && portWaferSize == WaferSize.Inch_8) || (portInfo.Size == WaferSize.Inch_12 && portWaferSize == WaferSize.Inch_12)))
        //                        {
        //                            Kernel.SecsEquip.Even.Ev_PortFoupStates(portNO, PortFoupStatus_KE.Loaded);
        //                        }

        //                        if (SecsDataHelper.Function.LoadPortAdapWhole)
        //                        {
        //                            if (portHelper.IO.FOUPClampStatus == 1 && portInfo.Enable)
        //                            {
        //                                Kernel.SecsEquip.Even.Ev_PortFoupStates(portNO, PortFoupStatus_KE.Clamp);
        //                            }
        //                            else if (portHelper.IO.FOUPClampStatus == 0 && portInfo.Enable)
        //                            {
        //                                Kernel.SecsEquip.Even.Ev_PortFoupStates(portNO, PortFoupStatus_KE.UnClamp);
        //                            }

        //                            if (portHelper.IO.DoorPosition == 0 && portInfo.Enable)
        //                            {
        //                                Kernel.SecsEquip.Even.Ev_PortFoupStates(portNO, PortFoupStatus_KE.CarrierOpened);
        //                            }
        //                            else if (portHelper.IO.DoorPosition == 1 && portInfo.Enable)
        //                            {
        //                                Kernel.SecsEquip.Even.Ev_PortFoupStates(portNO, PortFoupStatus_KE.CarrierClosed);
        //                            }
        //                        }
        //                    }
        //                }
        //                else
        //                {
        //                    for (int i = 0; i < PortStates.Length; i++)
        //                    {
        //                        PortStatesBuf[i] = PortStates[i];
        //                    }
        //                }
        //            }

        //#endregion

        //        }

        public static List<ushort> ConvertMapData(List<MapData> MapDatas)
        {
            List<ushort> MapDatasRet = new List<ushort>();
            for (int i = 0; i < MapDatas.Count; i++)
            {
                MapDatasRet.Add(MapDatas[i].MappingRet);
            }
            return MapDatasRet;
        }

        /// <summary>
        /// 检查recipeName本地是否存在
        /// </summary>
        /// <param name="portNO"></param>
        /// <param name="recipeName"></param>
        /// <returns></returns>
        public static bool CheckRecipeName(int portNO, string recipeName)
        {
            //List<string> tRecipes = SearchRevs(portNO);

            //if (tRecipes.Count > 0)
            //{
            //    foreach (var item in tRecipes)
            //    {
            //        if (item == recipeName)
            //        {
            //            return true;
            //        }
            //    }
            //}
            return false;
        }


        //暂时pass  20250526
#if false

        private static List<string> SearchRevs(int portNO)
        {
            List<string> revs = new List<string>();
            WaferSize size = WaferSize.Inch_6;
            WaferType type = WaferType.Whole;

            switch (portNO)
            {
                case 1:
                    {
                        size = VisionCore.Efem.GlobalVars.PAInfo.Size;
                        type = VisionCore.Efem.GlobalVars.PAInfo.Type;
                    }
                    break;
                case 2:
                    {
                        size = VisionCore.Efem.GlobalVars.PBInfo.Size;
                        type = VisionCore.Efem.GlobalVars.PBInfo.Type;
                    }
                    break;
            }

            foreach (var item in VisionCore.EQ.GlobalVars.AllRecDatas)
            {
                if (item.Value.Type == type)
                {
                    if (type == WaferType.Frame && false)
                    {
                        switch (size)
                        {
                            case WaferSize.Inch_12:
                                if (item.Value.Size == WaferSize.Inch_12 || item.Value.Size == WaferSize.Inch_8 || item.Value.Size == WaferSize.Inch_6)
                                {
                                    revs.Add(item.Key);
                                }
                                break;
                            case WaferSize.Inch_8:
                                if (item.Value.Size == WaferSize.Inch_8 || item.Value.Size == WaferSize.Inch_6)
                                {
                                    revs.Add(item.Key);
                                }
                                break;
                            case WaferSize.Inch_6:
                                if (item.Value.Size == WaferSize.Inch_6)
                                {
                                    revs.Add(item.Key);
                                }
                                break;
                        }
                    }
                    else
                    {
                        if (item.Value.Size == size)
                        {
                            revs.Add(item.Key);
                        }
                    }
                }
            }

            return revs;
        }

        public static bool IsFocusUnloadFoup(PortInfo portinfo)
        {
            if (portinfo.SeEvenState.EAPRFIDVerifyRs == 2)
            {
                return true;
            }
            return false;
        }


        public static void CheckPortSelForSECS(bool en, PortName name)
        {
            if (!en) { return; }
            int selCount = 0;
            switch (name)
            {
                case PortName.PA:
                    VisionCore.Efem.Port.GlobalVars.PADataGridViewInit = true;
                    bool PAsel = true;
                    if (ParameterHelper.PortA.MapDatas.Count > 0)
                    {
                        for (int i = 0; i < ParameterHelper.PortA.MapDatas.Count; i++)
                        {
                            if (selCount >= 4)
                            {
                                break;
                            }
                            VisionCore.Efem.Port.GlobalVars.PA.Sels[i] = ParameterHelper.PortA.MapDatas[i].Valid;
                            if (VisionCore.Efem.Port.GlobalVars.PA.Sels[i])
                            {
                                selCount++;
                            }
                        }
                    }
                    break;
                case PortName.PB:
                    VisionCore.Efem.Port.GlobalVars.PBDataGridViewInit = true;
                    bool PBsel = true;
                    if (ParameterHelper.PortB.MapDatas.Count > 0)
                    {
                        for (int i = 0; i < ParameterHelper.PortB.MapDatas.Count; i++)
                        {
                            if (selCount >= 4)
                            {
                                break;
                            }
                            VisionCore.Efem.Port.GlobalVars.PB.Sels[i] = ParameterHelper.PortB.MapDatas[i].Valid;
                            if (VisionCore.Efem.Port.GlobalVars.PB.Sels[i])
                            {
                                selCount++;
                            }
                        }
                    }
                    break;
            }

        }
        /// <summary>
        /// 抽检层上报用
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static List<int> PortSelCount(PortName name)
        {
            List<int> selList = new List<int>();
            switch (name)
            {
                case PortName.PA:
                    for (int i = 0; i < VisionCore.Efem.Port.GlobalVars.PA.Sels.Count; i++)
                    {
                        if (VisionCore.Efem.Port.GlobalVars.PA.Sels[i])
                        {
                            selList.Add(1);
                        }
                        else
                        {
                            selList.Add(0);
                        }
                    }
                    break;
                case PortName.PB:
                    for (int i = 0; i < VisionCore.Efem.Port.GlobalVars.PB.Sels.Count; i++)
                    {
                        if (VisionCore.Efem.Port.GlobalVars.PB.Sels[i])
                        {
                            selList.Add(1);
                        }
                        else
                        {
                            selList.Add(0);
                        }
                    }
                    break;
            }
            return selList;
        }

#endif


        #region

        //public static Dictionary<string, List<double>> CheckMeasureData(Dictionary<string, List<double>> curMeasureDataList)
        //{
        //    Dictionary<string, List<double>> notMeasureDateList = new Dictionary<string, List<double>>();
        //    Dictionary<string, List<double>> resMeasureDateList = new Dictionary<string, List<double>>();
        //    foreach (var allShiftScanRoads in Insp.GlobalVars.ShiftScanRoadsForSECS)
        //    {
        //        bool isExist = false;
        //        string strDiePos = String.Format("R{0}_C{1}", allShiftScanRoads.DiePos_User.Y, allShiftScanRoads.DiePos_User.X);
        //        foreach (var realShiftScanRoads in curMeasureDataList)
        //        {
        //            if (realShiftScanRoads.Key.Length >= 5 && strDiePos.Equals(realShiftScanRoads.Key.Substring(0, 5)))
        //            {
        //                isExist = true;
        //            }
        //        }
        //        if (!isExist)
        //        {
        //            for (int i = 0; i < ParameterHelper.TrainParam.InspParam.ShiftMeasure.Progs.Count; i++)
        //            {
        //                List<double> list = new List<double>() { 0, 0, 40, 0 };
        //                string strName = String.Format("R{0}_C{1}_{2}", allShiftScanRoads.DiePos_User.Y, allShiftScanRoads.DiePos_User.X, i);
        //                if (!notMeasureDateList.ContainsKey(strName))
        //                {
        //                    notMeasureDateList.Add(strName, list);
        //                }
        //                else
        //                {
        //                    SeLogMsg("SECS: 检测Die数据字典中存在_1");
        //                }
        //            }
        //        }
        //    }
        //    foreach (var item in curMeasureDataList)
        //    {
        //        if (!resMeasureDateList.ContainsKey(item.Key))
        //        {
        //            resMeasureDateList.Add(item.Key, item.Value);
        //        }
        //        else
        //        {
        //            SeLogMsg("SECS: 检测Die数据字典中存在_2");
        //        }
        //    }
        //    foreach (var item in notMeasureDateList)
        //    {
        //        if (!resMeasureDateList.ContainsKey(item.Key))
        //        {
        //            resMeasureDateList.Add(item.Key, item.Value);
        //        }
        //        else
        //        {
        //            SeLogMsg("SECS: 检测Die数据字典中存在_3");
        //        }
        //    }
        //    return resMeasureDateList;

        //}




        //public static Dictionary<string, List<double>> CheckMeasureData(Dictionary<string, List<double>> curMeasureDataList)
        //{
        //    Dictionary<string, List<double>> notMeasureDateList = new Dictionary<string, List<double>>();
        //    Dictionary<string, List<double>> resMeasureDateList = new Dictionary<string, List<double>>();
        //    foreach (var allShiftScanRoads in Insp.GlobalVars.ShiftScanRoadsForSECS)
        //    {
        //        bool isExist = false;
        //        string strDiePos = String.Format("R{0:D2}_C{1:D2}", allShiftScanRoads.DiePos_User.Y, allShiftScanRoads.DiePos_User.X);
        //        foreach (var realShiftScanRoads in curMeasureDataList)
        //        {
        //            int index = realShiftScanRoads.Key.IndexOf("_");
        //            if (realShiftScanRoads.Key.Length >= index + 2 && strDiePos.Equals(realShiftScanRoads.Key.Substring(0, index + 2)))
        //            {
        //                isExist = true;
        //            }
        //        }
        //        if (!isExist)
        //        {
        //            if (ParameterHelper.TrainParam.InspParam.ShiftMeasure.BaseToFirstEnable)
        //            {
        //                for (int i = 0; i < ParameterHelper.TrainParam.InspParam.ShiftMeasure.Progs.Count; i++)
        //                {
        //                    for (int j = 0; j < ParameterHelper.TrainParam.InspParam.ShiftMeasure.Progs[i].Points.Count; j++)
        //                    {
        //                        List<double> list = new List<double>() { 0, 0, 40, 0 };
        //                        string strName = String.Format("R{0:D2}_C{1:D2}_{2:D2}_{3:D2}", allShiftScanRoads.DiePos_User.Y, allShiftScanRoads.DiePos_User.X, i, j);
        //                        if (!notMeasureDateList.ContainsKey(strName))
        //                        {
        //                            notMeasureDateList.Add(strName, list);
        //                        }
        //                        else
        //                        {
        //                            SeLogMsg("SECS: 检测Die数据字典中存在_1");
        //                        }
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                for (int i = 0; i < ParameterHelper.TrainParam.InspParam.ShiftMeasure.Progs.Count; i++)
        //                {
        //                    List<double> list = new List<double>() { 0, 0, 40, 0 };
        //                    string strName = String.Format("R{0:D2}_C{1:D2}_{2:D2}", allShiftScanRoads.DiePos_User.Y, allShiftScanRoads.DiePos_User.X, i);
        //                    if (!notMeasureDateList.ContainsKey(strName))
        //                    {
        //                        notMeasureDateList.Add(strName, list);
        //                    }
        //                    else
        //                    {
        //                        SeLogMsg("SECS: 检测Die数据字典中存在_2");
        //                    }
        //                }
        //            }
        //        }
        //    }
        //    foreach (var item in curMeasureDataList)
        //    {
        //        if (!resMeasureDateList.ContainsKey(item.Key))
        //        {
        //            resMeasureDateList.Add(item.Key, item.Value);
        //        }
        //        else
        //        {
        //            SeLogMsg("SECS: 检测Die数据字典中存在_3");
        //        }
        //    }
        //    foreach (var item in notMeasureDateList)
        //    {
        //        if (!resMeasureDateList.ContainsKey(item.Key))
        //        {
        //            resMeasureDateList.Add(item.Key, item.Value);
        //        }
        //        else
        //        {
        //            SeLogMsg("SECS: 检测Die数据字典中存在_4");
        //        }
        //    }
        //    return resMeasureDateList;
        //}



        public static Dictionary<string, List<double>> CheckMeasureData(Dictionary<string, List<double>> curMeasureDataList)
        {
            if (curMeasureDataList ==null)
            {
                SeLogMsg("ERR: curMeasureDataList数据为空");
                return null;
            }
            Dictionary<string, List<double>> notMeasureDateList = new Dictionary<string, List<double>>();
            Dictionary<string, List<double>> resMeasureDateList = new Dictionary<string, List<double>>();

            //暂时pass  20250526

            //foreach (var allShiftScanRoads in Insp.GlobalVars.ShiftScanRoadsForSECS)
            //{
            //    bool isExist = false;
            //    string strDiePos = String.Format("R{0:D2}_C{1:D2}", allShiftScanRoads.DiePos_User.Y, allShiftScanRoads.DiePos_User.X);
            //    foreach (var realShiftScanRoads in curMeasureDataList)
            //    {
            //        int index = realShiftScanRoads.Key.IndexOf("_");
            //        if (realShiftScanRoads.Key.Length >= index + 2 && strDiePos.Equals(realShiftScanRoads.Key.Substring(0, index + 2)))
            //        {
            //            isExist = true;
            //        }
            //    }
            //    if (!isExist)
            //    {
            //        for (int i = 0; i < ParameterHelper.TrainParam.InspParam.ShiftMeasure.Progs.Count; i++)
            //        {
            //            if (/*ParameterHelper.TrainParam.InspParam.ShiftMeasure.Progs[i].ProgEnable*/ true)//20240906修改
            //            {
            //                foreach (var item in ParameterHelper.TrainParam.InspParam.ShiftMeasure.Progs[i].Dic_Methods)
            //                {
            //                    List<double> list = new List<double>() { 0, 0, 40, 0 };
            //                    string strName = String.Format("R{0:D2}_C{1:D2}_Progs{2:D2}_Regions{3:D2}", allShiftScanRoads.DiePos_User.Y, allShiftScanRoads.DiePos_User.X, i, item.Key);
            //                    if (!notMeasureDateList.ContainsKey(strName))
            //                    {
            //                        notMeasureDateList.Add(strName, list);
            //                    }
            //                    else
            //                    {
            //                        SeLogMsg("ERR: 检测Die数据字典中存在_1");
            //                    }
            //                }
            //            }
            //        }

            //    }
            //}

            resMeasureDateList = new Dictionary<string, List<double>>(curMeasureDataList);
            foreach (var item in notMeasureDateList)
            {
                if (!resMeasureDateList.ContainsKey(item.Key))
                {
                    resMeasureDateList.Add(item.Key, item.Value);
                }
                else
                {
                    SeLogMsg("ERR: 检测Die数据字典中存在_4");
                }
            }
            return resMeasureDateList;
        }
#endregion

        public static bool CopyMapFile(string waferMapName, string markID, PortInfo portInfo)
        {
            string aimPath = FilePathHelper.GetWaferMap_Dir(portInfo.DeviceName, true, portInfo.LotNo);

            string sourPath = ""/*ParameterHelper.SysParam.FilePath.MapDataFileDir_EAP*/;  //"\\\\10.107.108.13\\TD_Map_Data\\Diebond\\Input\\TSV Map\\Normal file path";
            string fullSourPath = sourPath + "\\" + waferMapName + ".sinf";
            string fullAimPath = aimPath + "\\" + markID + ".sinf";
            try
            {
                if (!Directory.Exists(aimPath))
                {
                    Directory.CreateDirectory(aimPath);
                }

                File.Copy(fullSourPath, fullAimPath, true);
                SeLogMsg("SUCC: Map复制成功");
                return true;
            }
            catch (Exception ex)
            {
                if (!Directory.Exists(sourPath))
                {
                    SeLogMsg("ERR: Map复制失败,Map路径访问失败");
                }
                else
                {
                    SeLogMsg("ERR: Map复制失败，Map文件未找到");
                }
                SeLogMsg(ex.Message);
                return false;
            }

        }

        public static void GetAVIProg()
        {
            string recipeDir = SecsParameterHelper.SecsParam.ProcessProgramPath;
            List<string> listRecipeName = UtilitiesFile.GetAllFolderName(recipeDir);
            try
            {
                foreach (string RecipeName in listRecipeName)
                {
                    string sourPath = string.Format(@"{0}\{1}\{2}.dat", ParameterHelper.SysParam.FilePath.ShareFileDir, RecipeName, ParameterHelper.SysParam.FilePath.AVIProgFileName);
                    string destPath = string.Format(@"{0}\{1}\{2}\{3}.pra", recipeDir, RecipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName, ParameterHelper.SysParam.FilePath.AVIProgFileName);
                    if (File.Exists(sourPath))
                    {
                        File.Copy(sourPath, destPath, true);
                    }

                }
            }
            catch (Exception ex)
            {

            }
        }
#region Recipe上传

#region 检测设备
        //public static Dictionary<string, object> ReadRecipeBody(string recipeName)
        //{
        //    Dictionary<string, object> dictRecipe = new Dictionary<string, object>();
        //    try
        //    {
        //        string recipeMotionFullPath = string.Format(@"{0}\{1}\{2}\Recipe.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName);
        //        string recipeAVIFullPath = string.Format(@"{0}\{1}\{2}\{3}.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName, ParameterHelper.SysParam.FilePath.AVIProgFileName);
        //        if (File.Exists(recipeMotionFullPath))
        //        {
        //            string tData = File.ReadAllText(recipeMotionFullPath);
        //            TrainModel aoiprmT = JsonConvert.DeserializeObject<TrainModel>(tData);
        //            dictRecipe.Add("TrainModel", aoiprmT);
        //        }
        //        if (File.Exists(recipeAVIFullPath))
        //        {
        //            string tData = File.ReadAllText(recipeAVIFullPath);
        //            SECSParm.PRM_WaferAOI aoiprmT = JsonConvert.DeserializeObject<SECSParm.PRM_WaferAOI>(tData);
        //            dictRecipe.Add("PRM_WaferAOI", aoiprmT);
        //        }
        //        return dictRecipe;
        //    }
        //    catch (Exception ex)
        //    {
        //        return null;
        //    }
        //}

        //private static Dictionary<string, Dictionary<string, string>> GetRecipeItem(Dictionary<string, object> dictRecipeBody)
        //{
        //    if (dictRecipeBody.Count < 2)
        //    {
        //        return null;
        //    }
        //    Dictionary<string, Dictionary<string, string>> dictRecipeItem = new Dictionary<string, Dictionary<string, string>>
        //    {
        //        { "InspParam", new Dictionary<string, string>() },
        //        { "Light", new Dictionary<string, string>() },
        //        { "WfInfo", new Dictionary<string, string>() },
        //        { "AVIParam", new Dictionary<string, string>() }
        //    };

        //    TrainModel trainModel = (TrainModel)dictRecipeBody["TrainModel"];

        //    string strLenGP_Insp = "LensGP_A";
        //    if (trainModel.InspParam.LenGP_Insp.ToString() == "镜组A")//EAP不能接收中文，改英文
        //    {
        //        strLenGP_Insp = "LenGP_A";
        //    }
        //    else if (trainModel.InspParam.LenGP_Insp.ToString() == "镜组B")
        //    {
        //        strLenGP_Insp = "LenGP_B";
        //    }
        //    dictRecipeItem["InspParam"].Add("CheckWaferID", trainModel.InspParam.CheckWaferID.ToString());
        //    dictRecipeItem["InspParam"].Add("ReInspLens", trainModel.InspParam.ReInspLens.ToString());
        //    dictRecipeItem["InspParam"].Add("LenGP_Insp", strLenGP_Insp);
        //    dictRecipeItem["InspParam"].Add("InspLens_B", trainModel.InspParam.InspLens_B.ToString());

        //    dictRecipeItem["Light"].Add("ReInsp_BF", trainModel.Light.ReInsp_DF.ToString());
        //    dictRecipeItem["Light"].Add("Insp_BF", trainModel.Light.Insp_BF.ToString());
        //    dictRecipeItem["Light"].Add("Insp_DF", trainModel.Light.Insp_DF.ToString());

        //    dictRecipeItem["WfInfo"].Add("WfType", ((int)trainModel.WfInfo.WfType).ToString());
        //    dictRecipeItem["WfInfo"].Add("WfSize", ((int)trainModel.WfInfo.WfSize).ToString());
        //    dictRecipeItem["WfInfo"].Add("NotchDir_Map", ((int)trainModel.WfInfo.NotchDir_Map).ToString());
        //    dictRecipeItem["WfInfo"].Add("NotchDir_EQ", ((int)trainModel.WfInfo.NotchDir_EQ).ToString());
        //    dictRecipeItem["WfInfo"].Add("DieSizeWidth", trainModel.WfInfo.DieSizeWidth.ToString());
        //    dictRecipeItem["WfInfo"].Add("DieSizeHeight", trainModel.WfInfo.DieSizeHeight.ToString());
        //    dictRecipeItem["WfInfo"].Add("ColSize", trainModel.WfInfo.ColSize.ToString());
        //    dictRecipeItem["WfInfo"].Add("RowSize", trainModel.WfInfo.RowSize.ToString());
        //    dictRecipeItem["WfInfo"].Add("DisCenterDieToCircleX", trainModel.WfInfo.DisCenterDieToCircleX.ToString());
        //    dictRecipeItem["WfInfo"].Add("DisCenterDieToCircleY", trainModel.WfInfo.DisCenterDieToCircleY.ToString());
        //    dictRecipeItem["WfInfo"].Add("CenterDieColIdx", trainModel.WfInfo.CenterDieColIdx.ToString());
        //    dictRecipeItem["WfInfo"].Add("CenterDieRowIdx", trainModel.WfInfo.CenterDieRowIdx.ToString());
        //    dictRecipeItem["WfInfo"].Add("CutLineWidth", trainModel.WfInfo.CutLineWidth.ToString());
        //    dictRecipeItem["WfInfo"].Add("CutLineHight", trainModel.WfInfo.CutLineHight.ToString());


        //    SECSParm.PRM_WaferAOI prm_WaferAOI = (SECSParm.PRM_WaferAOI)dictRecipeBody["PRM_WaferAOI"];
        //    foreach (var Prog in prm_WaferAOI.Progs)
        //    {
        //        string nameProg = string.Format($"Progs[{Prog.Key.ToString()}]");
        //        foreach (var Seg in Prog.Value.AOIParas)
        //        {
        //            string nameSeg = nameProg + string.Format($".Segs[{Seg.Key.ToString()}]");
        //            for (int i = 0; i < Seg.Value.DetectROIs.Count; i++)
        //            {
        //                string nameDetectROI = nameSeg + string.Format($".Regions[{i}].");
        //                dictRecipeItem["AVIParam"].Add(nameDetectROI + "DetectClassificationName", Seg.Value.DetectROIs[i].DetectClassificationName.ToString());
        //                if (Seg.Value.DetectROIs[i].DetectClassificationName.ToString() == "4.Chipping" || Seg.Value.DetectROIs[i].DetectClassificationName.ToString() == "5.Chipping_inner")
        //                {
        //                    string strChipping_Shield = "不屏蔽";
        //                    switch (Seg.Value.DetectROIs[i].Chipping_Shield.ToString())
        //                    {
        //                        case "不屏蔽":
        //                            {
        //                                strChipping_Shield = "UnShield";
        //                            }
        //                            break;
        //                        case "上":
        //                            {
        //                                strChipping_Shield = "Up";
        //                            }
        //                            break;
        //                        case "下":
        //                            {
        //                                strChipping_Shield = "Down";
        //                            }
        //                            break;
        //                        case "左":
        //                            {
        //                                strChipping_Shield = "Left";
        //                            }
        //                            break;
        //                        case "右":
        //                            {
        //                                strChipping_Shield = "Right";
        //                            }
        //                            break;
        //                        case "上下":
        //                            {
        //                                strChipping_Shield = "UpAndDown";
        //                            }
        //                            break;
        //                    }

        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Chipping_MinThres", Seg.Value.DetectROIs[i].Chipping_MinThres.ToString());
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Chipping_Shield", strChipping_Shield);
        //                }
        //                else if (Seg.Value.DetectROIs[i].DetectClassificationName.ToString() == "6.Measure_StreetWidth")
        //                {
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "MeasureStreetWidthRowSpliteNum", Seg.Value.DetectROIs[i].MeasureStreetWidthRowSpliteNum.ToString());
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "MeasureStreetWidthColSpliteNum", Seg.Value.DetectROIs[i].MeasureStreetWidthColSpliteNum.ToString());
        //                    //dictRecipeItem["AVIParam"].Add(name, Seg.Value.DetectROIs[i].MeasureStreetWidthShield.ToString());
        //                }
        //                else
        //                {
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Bright_MinDefectArea", Seg.Value.DetectROIs[i].Bright_MinDefectArea.ToString());
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Bright_MinDefectWidth", Seg.Value.DetectROIs[i].Bright_MinDefectWidth.ToString());
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Bright_MinDefectLength", Seg.Value.DetectROIs[i].Bright_MinDefectLength.ToString());
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Bright_MinContrastDalta", Seg.Value.DetectROIs[i].Bright_MinContrastDalta.ToString());

        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Dark_MinDefectArea", Seg.Value.DetectROIs[i].Dark_MinDefectArea.ToString());
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Dark_MinDefectWidth", Seg.Value.DetectROIs[i].Dark_MinDefectWidth.ToString());
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Dark_MinDefectLength", Seg.Value.DetectROIs[i].Dark_MinDefectLength.ToString());
        //                    dictRecipeItem["AVIParam"].Add(nameDetectROI + "Dark_MinContrastDalta", Seg.Value.DetectROIs[i].Dark_MinContrastDalta.ToString());
        //                }
        //                dictRecipeItem["AVIParam"].Add(nameDetectROI + "DefectReCheckCount", Seg.Value.DetectROIs[i].DefectReCheckCount.ToString());

        //            }
        //        }
        //    }

        //    return dictRecipeItem;

        //}

        //public static Dictionary<string, Dictionary<string, string>> GetRecipeItem(string recipeName)
        //{
        //    if (string.IsNullOrEmpty(recipeName))
        //    {
        //        return null;
        //    }
        //    Dictionary<string, object> dictRecipe = ReadRecipeBody(recipeName);
        //    if (dictRecipe == null)
        //    {
        //        return null;
        //    }
        //    Dictionary<string, Dictionary<string, string>> dictRecipeItem = GetRecipeItem(dictRecipe);
        //    return dictRecipeItem;
        //}
#endregion

#region 量测设备

        public static Dictionary<string, string> DictRecipeItemSend { get; set; } = new Dictionary<string, string>();
        public static Dictionary<string, string> DictRecipeItemTypeSend { get; set; } = new Dictionary<string, string>();
        private static void GetRecipeItem(object obj, string strName, ref Dictionary<string, string> dictRecipeItemTemp, ref Dictionary<string, string> dictRecipeItemTempType)
        {
            if (obj == null)
            {
                return;
            }

            Type trainType = obj.GetType();
            PropertyInfo[] trainPropertyInfos = trainType.GetProperties();
            if (trainType.IsCustomClass())
            {
                foreach (PropertyInfo trainPropertyInfo in trainPropertyInfos)
                {
                    string name = string.IsNullOrEmpty(strName) ? trainPropertyInfo.Name : strName + "." + trainPropertyInfo.Name;

                    Type propertyType = trainPropertyInfo.PropertyType;
                    bool isCustomClass = propertyType.IsCustomClass();
                    bool isArray = propertyType.IsArrayType();
                    bool isList = propertyType.IsListNotArray();
                    bool isDic = propertyType.IsDictionaryType();
                    if (isCustomClass)
                    {
                        GetRecipeItem(trainPropertyInfo.GetValue(obj), name, ref dictRecipeItemTemp, ref dictRecipeItemTempType);
                    }
                    else if (trainPropertyInfo.Name == "Point")
                    {
                        GetRecipeItem(trainPropertyInfo.GetValue(obj), name, ref dictRecipeItemTemp, ref dictRecipeItemTempType);
                    }
                    else if (isArray)
                    {
                        Type elementType = propertyType.GetElementType();
                        var array = (Array)trainPropertyInfo.GetValue(obj, null);
                        int n = 0;
                        foreach (var item in array)
                        {
                            GetRecipeItem(item, name + $"[{n}]", ref dictRecipeItemTemp, ref dictRecipeItemTempType);
                            n++;
                        }
                    }
                    else if (isList)
                    {
                        Type[] genericArguments = propertyType.GetGenericArguments();
                        var list = (IList)trainPropertyInfo.GetValue(obj, null);
                        int n = 0;
                        foreach (var item in list)
                        {
                            GetRecipeItem(item, name + $"[{n}]", ref dictRecipeItemTemp, ref dictRecipeItemTempType);
                            n++;
                        }
                    }
                    else if (isDic)
                    {
                        Type keyType = propertyType.GetGenericArguments()[0];
                        Type valueType = propertyType.GetGenericArguments()[1];
                        var dec = (IDictionary)trainPropertyInfo.GetValue(obj, null);
                        foreach (DictionaryEntry item in dec)
                        {
                            GetRecipeItem(item.Value, name + $"[{item.Key}]", ref dictRecipeItemTemp, ref dictRecipeItemTempType);
                        }
                    }
                    else
                    {
                        Dictionary<string, string> item = new Dictionary<string, string>();
                        dictRecipeItemTemp.Add(name, trainPropertyInfo.GetValue(obj).ToString());
                        dictRecipeItemTempType.Add(name, trainPropertyInfo.PropertyType.Name);
                    }
                }
            }
            else if (!trainType.IsCustomClass() /*|| trainPropertyInfos.Length <= 0*/)
            {
                if (trainType.Name == "Point")
                {
                    PropertyInfo[] propertyInfos = trainType.GetProperties();
                    foreach (var item in propertyInfos)
                    {
                        var value = item.GetValue(obj, null);
                        GetRecipeItem(value, strName + $".{item.Name}", ref dictRecipeItemTemp, ref dictRecipeItemTempType);
                    }
                }
                else
                {
                    dictRecipeItemTemp.Add(strName, obj.ToString());
                    dictRecipeItemTempType.Add(strName, obj.GetType().Name);
                }
            }

        }

        public static Dictionary<string, Dictionary<string, string>> OnGetRecipeItem(string recipeName, out Dictionary<string, Dictionary<string, string>> recipeItemDecType)
        {
            Dictionary<string, Dictionary<string, string>> dictRecipeItem = new Dictionary<string, Dictionary<string, string>>();
            recipeItemDecType = new Dictionary<string, Dictionary<string, string>>();
            if (string.IsNullOrEmpty(recipeName))
            {
                return null;
            }
            Dictionary<string, object> dictRecipe = ReadRecipeBody(recipeName);
            if (dictRecipe == null || dictRecipe.Count == 0)
            {
                return null;
            }

            RecipeModel recipeModel = (RecipeModel)dictRecipe["RecipeModel"];
            TrainModel trainModel = (TrainModel)dictRecipe["TrainModel"];

            Dictionary<string, string> dictRecipeItemTemp = new Dictionary<string, string>();
            Dictionary<string, string> dictRecipeItemTypeTemp = new Dictionary<string, string>();

            Dictionary<string, string> dictRecipeTrainItemTemp = new Dictionary<string, string>();
            Dictionary<string, string> dictRecipeTrainItemTypeTemp = new Dictionary<string, string>();

            GetRecipeItem(recipeModel, "RecipeModel", ref dictRecipeItemTemp, ref dictRecipeItemTypeTemp);
            GetRecipeItem(trainModel, "TrainModel", ref dictRecipeTrainItemTemp, ref dictRecipeTrainItemTypeTemp);

            Dictionary<string, string> dictRecipeItemTempAllEn = ChineseToEnglishDic(dictRecipeItemTemp);
            Dictionary<string, string> dictRecipeTrainItemTempAllEn = ChineseToEnglishDic(dictRecipeTrainItemTemp);

            dictRecipeItem.Add("RecipeModel", dictRecipeItemTempAllEn);
            dictRecipeItem.Add("TrainModel", dictRecipeTrainItemTempAllEn);

            recipeItemDecType.Add("RecipeModel", dictRecipeItemTypeTemp);
            recipeItemDecType.Add("TrainModel", dictRecipeTrainItemTypeTemp);

            return dictRecipeItem;
        }
        public static Dictionary<string, object> ReadRecipeBody(string recipeName)
        {
            Dictionary<string, object> dictRecipe = new Dictionary<string, object>();
            try
            {
                string recipeRecipeFullPath = string.Format(@"{0}\{1}\Recipe.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName);
                string trainRecipeFullPath = string.Format(@"{0}\{1}\{2}\Recipe.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName);

                if (File.Exists(recipeRecipeFullPath))
                {
                    string tData = File.ReadAllText(recipeRecipeFullPath);
                    RecipeModel recipeModel = JsonConvert.DeserializeObject<RecipeModel>(tData);
                    dictRecipe.Add("RecipeModel", recipeModel);
                }
                else
                {
                    SeLogMsg($"ERR: Recipe文件{recipeRecipeFullPath}未找到！");
                }
                if (File.Exists(trainRecipeFullPath))
                {
                    string tData = File.ReadAllText(trainRecipeFullPath);
                    TrainModel trainModel = JsonConvert.DeserializeObject<TrainModel>(tData);
                    dictRecipe.Add("TrainModel", trainModel);
                }
                else
                {
                    SeLogMsg($"ERR: Recipe文件{trainRecipeFullPath}未找到！");
                }
                return dictRecipe;
            }
            catch (Exception ex)
            {
                return null;
            }
        }


        [Obsolete]
        private static Dictionary<string, Dictionary<string, string>> GetRecipeItem(Dictionary<string, object> dictRecipeBody)
        {
            if (dictRecipeBody.Count < 1)
            {
                return null;
            }
            Dictionary<string, Dictionary<string, string>> dictRecipeItem = new Dictionary<string, Dictionary<string, string>>
            {
                { "InspParam", new Dictionary<string, string>() },
                { "Light", new Dictionary<string, string>() },
                { "WfInfo", new Dictionary<string, string>() },
            };

            TrainModel trainModel = (TrainModel)dictRecipeBody["TrainModel"];

            string strLenGP_Insp = "LensGP_A";


            //暂时pass  20250526
            //if (trainModel.InspParam.GPSel_Insp.GP.ToString() == "镜组A")//EAP不能接收中文，改英文
            //{
            //    strLenGP_Insp = "LenGP_A";
            //}
            //else if (trainModel.InspParam.GPSel_Insp.GP.ToString() == "镜组B")
            //{
            //    strLenGP_Insp = "LenGP_B";
            //}
            //dictRecipeItem["InspParam"].Add("InspParam.GPSel_Insp.GP", strLenGP_Insp);
            //dictRecipeItem["InspParam"].Add("InspParam.GPSel_Insp.Cam", trainModel.InspParam.GPSel_Insp.Cam);
            //dictRecipeItem["InspParam"].Add("InspParam.GPSel_Insp.Len", trainModel.InspParam.GPSel_Insp.Len);
            ////dictRecipeItem["InspParam"].Add("InspParam.OCR.Enable", trainModel.InspParam.OCR.Enable.ToString());
            ////dictRecipeItem["InspParam"].Add("InspParam.OCR.CheckWaferID", trainModel.InspParam.OCR.CheckWaferID.ToString());
            ////dictRecipeItem["InspParam"].Add("InspParam.OCR.CheckLotNo", trainModel.InspParam.OCR.CheckLotNo.ToString());

            //dictRecipeItem["Light"].Add("Light.ReInsp_BF", trainModel.Light.ReInsp_DF.ToString());
            //dictRecipeItem["Light"].Add("Light.Insp_BF", trainModel.Light.Insp_BF.ToString());
            //dictRecipeItem["Light"].Add("Light.Insp_DF", trainModel.Light.Insp_DF.ToString());

            //dictRecipeItem["WfInfo"].Add("WfInfo.WfType", ((int)trainModel.WfInfo.WfType).ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.WfSize", ((int)trainModel.WfInfo.WfSize).ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.NotchDir_Map", ((int)trainModel.WfInfo.NotchDir_Map).ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.NotchDir_EQ", ((int)trainModel.WfInfo.NotchDir_EQ).ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.DieSizeWidth", trainModel.WfInfo.DieSizeWidth.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.DieSizeHeight", trainModel.WfInfo.DieSizeHeight.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.ColSize", trainModel.WfInfo.ColSize.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.RowSize", trainModel.WfInfo.RowSize.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.DisCenterDieToCircleX", trainModel.WfInfo.DisCenterDieToCircleX.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.DisCenterDieToCircleY", trainModel.WfInfo.DisCenterDieToCircleY.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.CenterDieColIdx", trainModel.WfInfo.CenterDieColIdx.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.CenterDieRowIdx", trainModel.WfInfo.CenterDieRowIdx.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.CutLineWidth", trainModel.WfInfo.CutLineWidth.ToString());
            //dictRecipeItem["WfInfo"].Add("WfInfo.CutLineHight", trainModel.WfInfo.CutLineHight.ToString());

            return dictRecipeItem;

        }

#endregion

#endregion

#region Recipe下载

#region 检测设备
        //private static void SetRecipeItem(string recipeName, Dictionary<string, Dictionary<string, string>> dictRecipeItem, out TrainModel trainModel, out PRM_WaferAOI pRM_WaferAOI)
        //{
        //    Dictionary<string, object> dictRecipeRead = ReadRecipeBody(recipeName);
        //    trainModel = (TrainModel)dictRecipeRead["TrainModel"];
        //    pRM_WaferAOI = (PRM_WaferAOI)dictRecipeRead["PRM_WaferAOI"];

        //    try
        //    {
        //        trainModel.InspParam.CheckWaferID = Convert.ToBoolean(dictRecipeItem["InspParam"]["CheckWaferID"]);
        //        trainModel.InspParam.ReInspLens = dictRecipeItem["InspParam"]["ReInspLens"].ToString();
        //        trainModel.InspParam.LenGP_Insp = dictRecipeItem["InspParam"]["LenGP_Insp"].ToString();
        //        trainModel.InspParam.InspLens_B = dictRecipeItem["InspParam"]["InspLens_B"].ToString();

        //        trainModel.Light.ReInsp_BF = UtilitiesConvert.StringToInt(dictRecipeItem["Light"]["ReInsp_BF"]);
        //        trainModel.Light.Insp_BF = UtilitiesConvert.StringToInt(dictRecipeItem["Light"]["Insp_BF"]);
        //        trainModel.Light.Insp_DF = UtilitiesConvert.StringToInt(dictRecipeItem["Light"]["Insp_DF"]);

        //        trainModel.WfInfo.WfType = (WaferType)UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["WfType"]);
        //        trainModel.WfInfo.WfSize = (WaferSize)UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["WfSize"]);
        //        trainModel.WfInfo.NotchDir_Map = (NotchDir)UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["NotchDir_Map"]);
        //        trainModel.WfInfo.NotchDir_EQ = (NotchDir)UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["NotchDir_EQ"]);
        //        trainModel.WfInfo.DieSizeWidth = UtilitiesConvert.StringToDouble(dictRecipeItem["WfInfo"]["DieSizeWidth"]);
        //        trainModel.WfInfo.DieSizeHeight = UtilitiesConvert.StringToDouble(dictRecipeItem["WfInfo"]["DieSizeHeight"]);
        //        trainModel.WfInfo.ColSize = UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["ColSize"]);
        //        trainModel.WfInfo.RowSize = UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["RowSize"]);
        //        trainModel.WfInfo.DisCenterDieToCircleX = UtilitiesConvert.StringToDouble(dictRecipeItem["WfInfo"]["DisCenterDieToCircleX"]);
        //        trainModel.WfInfo.DisCenterDieToCircleY = UtilitiesConvert.StringToDouble(dictRecipeItem["WfInfo"]["DisCenterDieToCircleY"]);
        //        trainModel.WfInfo.CenterDieColIdx = UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["CenterDieColIdx"]);
        //        trainModel.WfInfo.CenterDieRowIdx = UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["CenterDieRowIdx"]);
        //        trainModel.WfInfo.CutLineWidth = UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["CutLineWidth"]);
        //        trainModel.WfInfo.CutLineHight = UtilitiesConvert.StringToInt(dictRecipeItem["WfInfo"]["CutLineHight"]);
        //    }
        //    catch (Exception ex)
        //    {

        //    }

        //}

        //public static bool SaveRecipeBody(string recipeName, TrainModel trainModel, PRM_WaferAOI pRM_WaferAOI)
        //{
        //    try
        //    {
        //        string recipeMotionPath = string.Format(@"{0}\{1}\{2}\", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName);

        //        string sorRecipeMotionFullPath = string.Format(@"{0}\{1}\{2}\Recipe.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName);
        //        string sisRecipeMotionFullPath = string.Format(@"{0}\{1}\{2}\Recipe_bak{3}.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName, DateTime.Now.ToString("yyyyMMddHHmmss"));
        //        string sorRecipeAVIFullPath = string.Format(@"{0}\{1}\{2}\{3}.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName, ParameterHelper.SysParam.FilePath.AVIProgFileName);
        //        string disRecipeAVIFullPath = string.Format(@"{0}\{1}\{2}\{3}_bak{4}.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName, ParameterHelper.SysParam.FilePath.AVIProgFileName, DateTime.Now.ToString("yyyyMMddHHmmss"));

        //        if (!Directory.Exists(recipeMotionPath))
        //        {
        //            Directory.CreateDirectory(recipeMotionPath);
        //        }

        //        if (File.Exists(sorRecipeMotionFullPath))
        //        {
        //            File.Copy(sorRecipeMotionFullPath, sisRecipeMotionFullPath);
        //        }
        //        string tMData = JsonConvert.SerializeObject(trainModel, Formatting.Indented);
        //        File.WriteAllText(sorRecipeMotionFullPath, tMData);

        //        if (File.Exists(sorRecipeAVIFullPath))
        //        {
        //            File.Copy(sorRecipeAVIFullPath, disRecipeAVIFullPath);
        //        }
        //        string tVData = JsonConvert.SerializeObject(pRM_WaferAOI, Formatting.Indented);
        //        File.WriteAllText(sorRecipeAVIFullPath, tVData);

        //        return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        return false;
        //    }
        //}

        //public static bool SetRecipeItem(string recipeName, Dictionary<string, Dictionary<string, string>> dictRecipeItem)
        //{
        //    if (string.IsNullOrEmpty(recipeName))
        //    {
        //        return false;
        //    }
        //    TrainModel trainModel;
        //    PRM_WaferAOI pRM_WaferAOI;
        //    SetRecipeItem(recipeName, dictRecipeItem, out trainModel, out pRM_WaferAOI);
        //    bool bRes = SaveRecipeBody(recipeName, trainModel, pRM_WaferAOI);
        //    return bRes;
        //}
#endregion

#region 量测设备

        public static Dictionary<string, string> DictRecipeItemRec { get; set; } = new Dictionary<string, string>();
        public static Dictionary<string, string> DictRecipeItemTypeRec { get; set; } = new Dictionary<string, string>();
        private static void SetRecipeItem(object objPre, object obj, string strName, ref Dictionary<string, string> dictRecipeItemTemp, ref Dictionary<string, string> dictRecipeItemTypeTemp)
        {
            if (obj == null)
            {
                return;
            }

            Type trainType = obj.GetType();
            PropertyInfo[] trainPropertyInfos = trainType.GetProperties();

            foreach (PropertyInfo trainPropertyInfo in trainPropertyInfos)
            {
                string name = string.IsNullOrEmpty(strName) ? trainPropertyInfo.Name : strName + "." + trainPropertyInfo.Name;

                Type propertyType = trainPropertyInfo.PropertyType;
                bool isCustomClass = propertyType.IsCustomClass();
                bool isArray = propertyType.IsArrayType();
                bool isList = propertyType.IsListNotArray();
                bool isDic = propertyType.IsDictionaryType();

                if (isCustomClass)
                {
                    var inst = trainPropertyInfo.GetValue(obj);
                    SetRecipeItem(obj, inst, name, ref dictRecipeItemTemp, ref dictRecipeItemTypeTemp);
                }
                else if (propertyType.Name == "Point")
                {
                    var inst = trainPropertyInfo.GetValue(obj);
                    SetRecipeItem(obj, inst, name, ref dictRecipeItemTemp, ref dictRecipeItemTypeTemp);
                }
                else if (isArray)
                {
                    Type elementType = propertyType.GetElementType();
                    bool isCustomClassElement = elementType.IsCustomClass();

                    var array = (Array)trainPropertyInfo.GetValue(obj, null);
                    Type type = array.GetType();

                    int n = 0;
                    foreach (var item in array)
                    {
                        if (isCustomClassElement)
                        {
                            var inst = item;
                            SetRecipeItem(obj, inst, name + $"[{n}]", ref dictRecipeItemTemp, ref dictRecipeItemTypeTemp);
                            n++;
                        }
                        else
                        {
                            MethodInfo setValueMethod = type.GetMethod("SetValue", new Type[] { typeof(object), typeof(int) });
                            foreach (var recipeItem in dictRecipeItemTemp)
                            {
                                string nameTemp = name + $"[{n}]";
                                if (nameTemp == recipeItem.Key)
                                {
                                    if (!dictRecipeItemTypeTemp.ContainsKey(nameTemp))
                                    {
                                        continue;
                                    }
                                    string typeName = dictRecipeItemTypeTemp[nameTemp];
                                    int index1 = nameTemp.LastIndexOf("[");
                                    int index2 = nameTemp.LastIndexOf("]");
                                    var strIndex = nameTemp.Substring(index1 + 1, index2 - index1 - 1);
                                    int intIndex = UtilitiesConvert.StringToInt32(strIndex);
#region 设置值
                                    try
                                    {
                                        switch (typeName)
                                        {
                                            case "String":
                                                {
                                                    string value = recipeItem.Value;
                                                    setValueMethod.Invoke(array, new object[] { value, n });
                                                }
                                                break;
                                            case "Boolean":
                                                {
                                                    bool value = UtilitiesConvert.StrStrToBoolean(recipeItem.Value);
                                                    setValueMethod.Invoke(array, new object[] { value, n });
                                                }
                                                break;
                                            case "Int32":
                                                {
                                                    int value = UtilitiesConvert.StringToInt32(recipeItem.Value);
                                                    setValueMethod.Invoke(array, new object[] { value, n });
                                                }
                                                break;
                                            case "Int16":
                                                {
                                                    Int16 value = UtilitiesConvert.StringToInt16(recipeItem.Value);
                                                    setValueMethod.Invoke(array, new object[] { value, n });
                                                }
                                                break;
                                            case "UInt16":
                                                {
                                                    UInt16 value = UtilitiesConvert.StringToUInt16(recipeItem.Value);
                                                    setValueMethod.Invoke(array, new object[] { value, n });
                                                }
                                                break;
                                            case "UInt32":
                                                {
                                                    UInt32 value = UtilitiesConvert.StringToUInt32(recipeItem.Value);
                                                    setValueMethod.Invoke(array, new object[] { value, n });
                                                }
                                                break;
                                            case "Double":
                                                {
                                                    double value = UtilitiesConvert.StringToDouble(recipeItem.Value);
                                                    setValueMethod.Invoke(array, new object[] { value, n });
                                                }
                                                break;
                                            default:
                                                {
                                                    SeLogMsg($"ERR: 变量{typeName} 类型 {trainPropertyInfo.Name} 设置值{recipeItem.Value} 失败 -> 未找到对应设置方法");
                                                }
                                                break;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        SeLogMsg($"ERR: 变量{typeName} 类型 {trainPropertyInfo.Name} 设置值{recipeItem.Value} 失败 -> {ex.Message}");
                                    }
#endregion
                                }
                            }
                            n++;
                        }
                    }
                }
                else if (isList)
                {
                    Type[] genericArguments = propertyType.GetGenericArguments();
                    bool isCustomClassElement = UtilitiesType.IsCustomClass(genericArguments[0]);

                    var list = (IList)trainPropertyInfo.GetValue(obj, null);
                    Type type = list.GetType();

                    int n = 0;
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (isCustomClassElement)
                        {
                            var inst = list[i];
                            SetRecipeItem(obj, inst, name + $"[{n}]", ref dictRecipeItemTemp, ref dictRecipeItemTypeTemp);
                            n++;
                        }
                        else
                        {
                            MethodInfo setValueMethod = type.GetMethod("set_Item");
                            foreach (var recipeItem in dictRecipeItemTemp)
                            {
                                string nameTemp = name + $"[{n}]";
                                if (nameTemp == recipeItem.Key)
                                {
                                    if (!dictRecipeItemTypeTemp.ContainsKey(nameTemp))
                                    {
                                        continue;
                                    }
                                    string typeName = dictRecipeItemTypeTemp[nameTemp];
                                    int index1 = nameTemp.LastIndexOf("[");
                                    int index2 = nameTemp.LastIndexOf("]");
                                    var strIndex = nameTemp.Substring(index1 + 1, index2 - index1 - 1);
                                    int intIndex = UtilitiesConvert.StringToInt32(strIndex);
#region 设置值
                                    try
                                    {
                                        switch (typeName)
                                        {
                                            case "String":
                                                {
                                                    string value = recipeItem.Value;
                                                    setValueMethod.Invoke(list, new object[] { n, value });
                                                }
                                                break;
                                            case "Boolean":
                                                {
                                                    bool value = UtilitiesConvert.StrStrToBoolean(recipeItem.Value);
                                                    setValueMethod.Invoke(list, new object[] { n, value });
                                                }
                                                break;
                                            case "Int32":
                                                {
                                                    int value = UtilitiesConvert.StringToInt32(recipeItem.Value);
                                                    setValueMethod.Invoke(list, new object[] { n, value });
                                                }
                                                break;
                                            case "Int16":
                                                {
                                                    Int16 value = UtilitiesConvert.StringToInt16(recipeItem.Value);
                                                    setValueMethod.Invoke(list, new object[] { n, value });
                                                }
                                                break;
                                            case "UInt16":
                                                {
                                                    UInt16 value = UtilitiesConvert.StringToUInt16(recipeItem.Value);
                                                    setValueMethod.Invoke(list, new object[] { n, value });
                                                }
                                                break;
                                            case "UInt32":
                                                {
                                                    UInt32 value = UtilitiesConvert.StringToUInt32(recipeItem.Value);
                                                    setValueMethod.Invoke(list, new object[] { n, value });
                                                }
                                                break;
                                            case "Double":
                                                {
                                                    double value = UtilitiesConvert.StringToDouble(recipeItem.Value);
                                                    setValueMethod.Invoke(list, new object[] { n, value });
                                                }
                                                break;
                                            default:
                                                {
                                                    SeLogMsg($"ERR: 变量{typeName} 类型 {trainPropertyInfo.Name} 设置值{recipeItem.Value} 失败 -> 未找到对应设置方法");
                                                }
                                                break;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        SeLogMsg($"ERR: 变量{typeName} 类型 {trainPropertyInfo.Name} 设置值{recipeItem.Value} 失败 -> {ex.Message}");
                                    }
#endregion
                                }
                            }
                            n++;
                        }
                    }
                }
                else if (isDic)
                {
                    Type keyType = propertyType.GetGenericArguments()[0];
                    Type valueType = propertyType.GetGenericArguments()[1];
                    var dec = (IDictionary)trainPropertyInfo.GetValue(obj, null);
                    IDictionary decTemp = UtilitiesSundry.CopyDictionary(dec);
                    Type dictType = dec.GetType();
                    foreach (DictionaryEntry item in decTemp)
                    {
                        if (valueType.IsCustomClass())
                        {
                            var inst = item.Value;
                            SetRecipeItem(obj, inst, name + $"[{item.Key}]", ref dictRecipeItemTemp, ref dictRecipeItemTypeTemp);
                        }
                        else
                        {
                            PropertyInfo itemProperty = dictType.GetProperty("Item");

                            foreach (var recipeItem in dictRecipeItemTemp)
                            {
                                string nameTemp = name + $"[{item.Key}]";
                                if (nameTemp == recipeItem.Key)
                                {
                                    if (!dictRecipeItemTypeTemp.ContainsKey(nameTemp))
                                    {
                                        continue;
                                    }
                                    string typeName = dictRecipeItemTypeTemp[nameTemp];
#region 设置值
                                    try
                                    {
                                        switch (typeName)
                                        {
                                            case "String":
                                                {
                                                    string value = recipeItem.Value;
                                                    itemProperty.SetValue(dec, value, new object[] { item.Key });
                                                }
                                                break;
                                            case "Boolean":
                                                {
                                                    bool value = UtilitiesConvert.StrStrToBoolean(recipeItem.Value);
                                                    itemProperty.SetValue(dec, value, new object[] { item.Key });
                                                }
                                                break;
                                            case "Int32":
                                                {
                                                    int value = UtilitiesConvert.StringToInt32(recipeItem.Value);
                                                    itemProperty.SetValue(dec, value, new object[] { item.Key });
                                                }
                                                break;
                                            case "Int16":
                                                {
                                                    Int16 value = UtilitiesConvert.StringToInt16(recipeItem.Value);
                                                    itemProperty.SetValue(dec, value, new object[] { item.Key });
                                                }
                                                break;
                                            case "UInt16":
                                                {
                                                    UInt16 value = UtilitiesConvert.StringToUInt16(recipeItem.Value);
                                                    itemProperty.SetValue(dec, value, new object[] { item.Key });
                                                }
                                                break;
                                            case "UInt32":
                                                {
                                                    UInt32 value = UtilitiesConvert.StringToUInt32(recipeItem.Value);
                                                    itemProperty.SetValue(dec, value, new object[] { item.Key });
                                                }
                                                break;
                                            case "Double":
                                                {
                                                    double value = UtilitiesConvert.StringToDouble(recipeItem.Value);
                                                    itemProperty.SetValue(dec, value, new object[] { item.Key });
                                                }
                                                break;
                                            default:
                                                {
                                                    SeLogMsg($"ERR: 变量{typeName} 类型 {trainPropertyInfo.Name} 设置值{item.Value} 失败 -> 未找到对应设置方法");
                                                }
                                                break;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        SeLogMsg($"ERR: 变量{typeName} 类型 {trainPropertyInfo.Name} 设置值{item.Value} 失败 -> {ex.Message}");
                                    }
#endregion
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (var item in dictRecipeItemTemp)
                    {
                        if (name == item.Key)
                        {
                            SetRecipeItemValue(ref dictRecipeItemTypeTemp, trainPropertyInfo, item, ref obj, name);
                        }
                    }
                    /*值类型Point，设置新值后需要拿到值，在上层类重新赋值*/
                    if (trainType.Name == "Point")
                    {
                        var type = objPre.GetType();
                        var propInfos = type.GetProperties();
                        foreach (var item in propInfos)
                        {
                            var subType = item.PropertyType;
                            if (subType.Name == "Point")
                            {
                                item.SetValue(objPre, obj);
                            }
                        }
                    }
                    /****************************************************/
                }
            }
        }



        private static void SetRecipeItemValue(ref Dictionary<string, string> dictRecipeItemTypeTemp, PropertyInfo trainPropertyInfo, KeyValuePair<string, string> item, ref object obj, string name)
        {
            string typeName = dictRecipeItemTypeTemp[name];
            try
            {
                switch (typeName)
                {
                    case "String":
                        {
                            string n = item.Value;
                            trainPropertyInfo.SetValue(obj, n);
                        }
                        break;
                    case "Boolean":
                        {
                            bool n = UtilitiesConvert.StrStrToBoolean(item.Value);
                            trainPropertyInfo.SetValue(obj, n);
                        }
                        break;
                    case "Int32":
                        {
                            int n = UtilitiesConvert.StringToInt32(item.Value);
                            trainPropertyInfo.SetValue(obj, n);
                        }
                        break;
                    case "Double":
                        {
                            double n = UtilitiesConvert.StringToDouble(item.Value);
                            trainPropertyInfo.SetValue(obj, n);
                        }
                        break;
                    case "Int16":
                        {
                            Int16 n = UtilitiesConvert.StringToInt16(item.Value);
                            trainPropertyInfo.SetValue(obj, n);
                        }
                        break;
                    case "UInt16":
                        {
                            UInt16 n = UtilitiesConvert.StringToUInt16(item.Value);
                            trainPropertyInfo.SetValue(obj, n);
                        }
                        break;
                    case "UInt32":
                        {
                            UInt32 n = UtilitiesConvert.StringToUInt32(item.Value);
                            trainPropertyInfo.SetValue(obj, n);
                        }
                        break;
                    default:
                        {
                            SeLogMsg($"ERR: 变量: {trainPropertyInfo.Name}, 类型:{typeName}, 设置值: {item.Value} 失败 -> 未找到对应设置方法");
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                SeLogMsg($"ERR: 变量: {trainPropertyInfo.Name}, 类型: {typeName}, 设置值: {item.Value} 失败 -> {ex.Message}");
            }

        }


        public static bool OnSetRecipeItem(string recipeName, Dictionary<string, Dictionary<string, string>> dictRecipeItem)
        {
            if (string.IsNullOrEmpty(recipeName) || dictRecipeItem == null || dictRecipeItem.Count == 0)
            {
                return false;
            }
            TrainModel trainModel = new TrainModel(); ;
            RecipeModel recipeModel;
            SetRecipeItem(recipeName, dictRecipeItem, out recipeModel/*, out trainModel*/);
            bool bRes = SaveRecipeBody(recipeName, recipeModel, trainModel);
            return bRes;
        }
        private static void SetRecipeItem(string recipeName, Dictionary<string, Dictionary<string, string>> dictRecipeItem, out RecipeModel recipeModel/*, out TrainModel trainModel*/)
        {
            Dictionary<string, string> recipeModelDec = dictRecipeItem["RecipeModel"];
            Dictionary<string, string> trainModelDec = dictRecipeItem["TrainModel"];

            Dictionary<string, string> recipeModelDecTemp = EnglishToChineseDic(recipeModelDec);
            Dictionary<string, string> trainModelDecTemp = EnglishToChineseDic(trainModelDec);

            Dictionary<string, object> dictRecipeRead = ReadRecipeBody(recipeName);
            recipeModel = (RecipeModel)dictRecipeRead["RecipeModel"];
            //trainModel = (TrainModel)dictRecipeRead["TrainModel"];

            Dictionary<string, string> dictRecipeItemTemp = new Dictionary<string, string>();
            Dictionary<string, string> dictRecipeItemTypeTemp = new Dictionary<string, string>();

            Dictionary<string, string> dictRecipeTrainItemTemp = new Dictionary<string, string>();
            Dictionary<string, string> dictRecipeTrainItemTypeTemp = new Dictionary<string, string>();

            GetRecipeItem(recipeModel, "RecipeModel", ref dictRecipeItemTemp, ref dictRecipeItemTypeTemp);
            //GetRecipeItem(trainModel, "TrainModel", ref dictRecipeTrainItemTemp, ref dictRecipeTrainItemTypeTemp);

            SetRecipeItem(recipeModel, recipeModel, "RecipeModel", ref recipeModelDecTemp, ref dictRecipeItemTypeTemp);
            //SetRecipeItem(recipeModel, trainModel, "TrainModel", ref trainModelDecTemp, ref dictRecipeTrainItemTypeTemp);

            SeLogMsg($"SUCC: EAP PFormat工单: {recipeName} 更新到本地成功！");
        }

        public static bool SaveRecipeBody(string recipeName, RecipeModel recipeModel, TrainModel trainModel)
        {
            try
            {
                string recipeMotionPath = string.Format(@"{0}\{1}\", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName);
                string trainMotionPath = string.Format(@"{0}\{1}\{2}\", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName);

                string sourRecipeMotionFullPath = string.Format(@"{0}\{1}\Recipe.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName);
                string disRecipeMotionFullPath = string.Format(@"{0}\{1}\Recipe_bak{2}.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, DateTime.Now.ToString("yyyyMMddHHmmss"));
                string sourTrainMotionFullPath = string.Format(@"{0}\{1}\{2}\Recipe.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName);
                string disTrainMotionFullPath = string.Format(@"{0}\{1}\{2}\Recipe_bak{3}.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName, DateTime.Now.ToString("yyyyMMddHHmmss"));

                string sourRecipeAVIFullPath = string.Format(@"{0}\{1}\{2}\{3}.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName, ParameterHelper.SysParam.FilePath.AVIProgFileName);
                string disRecipeAVIFullPath = string.Format(@"{0}\{1}\{2}\{3}_bak{4}.pra", SecsParameterHelper.SecsParam.ProcessProgramPath, recipeName, ParameterHelper.SysParam.FilePath.WaferTrainFileName, ParameterHelper.SysParam.FilePath.AVIProgFileName, DateTime.Now.ToString("yyyyMMddHHmmss"));

                if (!Directory.Exists(recipeMotionPath))
                {
                    Directory.CreateDirectory(recipeMotionPath);
                }
                if (!Directory.Exists(trainMotionPath))
                {
                    Directory.CreateDirectory(trainMotionPath);
                }

                if (File.Exists(sourRecipeMotionFullPath))
                {
                    File.Copy(sourRecipeMotionFullPath, disRecipeMotionFullPath);
                }
                string tVData = JsonConvert.SerializeObject(recipeModel, Formatting.Indented);
                File.WriteAllText(sourRecipeMotionFullPath, tVData);

                if (File.Exists(sourTrainMotionFullPath))
                {
                    File.Copy(sourTrainMotionFullPath, disTrainMotionFullPath);
                }
                string tMData = JsonConvert.SerializeObject(trainModel, Formatting.Indented);
                File.WriteAllText(sourTrainMotionFullPath, tMData);

                SeLogMsg($"SUCC: EAP PFormat工单: {recipeName} 保存到本地成功！");
                return true;
            }
            catch (Exception ex)
            {
                SeLogMsg($"ERR: EAP PFormat工单: {recipeName} 保存到本地失败！-> {ex.Message}");
                return false;
            }
        }

       
        private static void SetRecipeItem(string recipeName, Dictionary<string, Dictionary<string, string>> dictRecipeItem, out TrainModel trainModel/*, out PRM_WaferAOI pRM_WaferAOI*/)
        {
            Dictionary<string, object> dictRecipeRead = ReadRecipeBody(recipeName);
            trainModel = (TrainModel)dictRecipeRead["TrainModel"];
            //pRM_WaferAOI = (PRM_WaferAOI)dictRecipeRead["PRM_WaferAOI"];  //暂时pass  20250526

            try
            {

                //  暂时pass  20250526

                //trainModel.InspParam.GPSel_Insp.GP = dictRecipeItem["InspParam"]["InspParam.GPSel_Insp.GP "].ToString();
                //trainModel.InspParam.GPSel_Insp.Cam = dictRecipeItem["InspParam"]["InspParam.GPSel_Insp.Cam"].ToString();
                //trainModel.InspParam.GPSel_Insp.Len = dictRecipeItem["InspParam"]["InspParam.GPSel_Insp.Len"].ToString();
                ////trainModel.InspParam.OCR.Enable = Convert.ToBoolean(dictRecipeItem["InspParam"]["InspParam.OCR.Enable"]);//20240906修改
                ////trainModel.InspParam.OCR.CheckWaferID = Convert.ToBoolean(dictRecipeItem["InspParam"]["InspParam.OCR.CheckWaferID"]);
                ////trainModel.InspParam.OCR.CheckLotNo = Convert.ToBoolean(dictRecipeItem["InspParam"]["InspParam.OCR.CheckLotNo"]);

                //trainModel.Light.ReInsp_BF = UtilitiesConvert.StringToInt32(dictRecipeItem["Light"]["Light.ReInsp_BF"]);
                //trainModel.Light.Insp_BF = UtilitiesConvert.StringToInt32(dictRecipeItem["Light"]["Light.Insp_BF"]);
                //trainModel.Light.Insp_DF = UtilitiesConvert.StringToInt32(dictRecipeItem["Light"]["Light.Insp_DF"]);

                //trainModel.WfInfo.WfType = (WaferType)UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.WfType"]);
                //trainModel.WfInfo.WfSize = (WaferSize)UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.WfSize"]);
                //trainModel.WfInfo.NotchDir_Map = (NotchDir)UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.NotchDir_Map"]);
                //trainModel.WfInfo.NotchDir_EQ = (NotchDir)UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.NotchDir_EQ"]);
                //trainModel.WfInfo.DieSizeWidth = UtilitiesConvert.StringToDouble(dictRecipeItem["WfInfo"]["WfInfo.DieSizeWidth"]);
                //trainModel.WfInfo.DieSizeHeight = UtilitiesConvert.StringToDouble(dictRecipeItem["WfInfo"]["WfInfo.DieSizeHeight"]);
                //trainModel.WfInfo.ColSize = UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.ColSize"]);
                //trainModel.WfInfo.RowSize = UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.RowSize"]);
                //trainModel.WfInfo.DisCenterDieToCircleX = UtilitiesConvert.StringToDouble(dictRecipeItem["WfInfo"]["WfInfo.DisCenterDieToCircleX"]);
                //trainModel.WfInfo.DisCenterDieToCircleY = UtilitiesConvert.StringToDouble(dictRecipeItem["WfInfo"]["WfInfo.DisCenterDieToCircleY"]);
                //trainModel.WfInfo.CenterDieColIdx = UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.CenterDieColIdx"]);
                //trainModel.WfInfo.CenterDieRowIdx = UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.CenterDieRowIdx"]);
                //trainModel.WfInfo.CutLineWidth = UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.CutLineWidth"]);
                //trainModel.WfInfo.CutLineHight = UtilitiesConvert.StringToInt32(dictRecipeItem["WfInfo"]["WfInfo.CutLineHight"]);
            }
            catch (Exception ex)
            {

            }

        }

#endregion

#endregion

        private static string[] chinese = new string[] { "镜组A", "镜组B", "可见光", "红外光", "扫描", "路径", "跑位", "行列", "圆周等角度", "圆周等弧长", "螺旋线" };
        private static string[] english = new string[] { "LenGP_A", "LenGP_B", "VisibleLight", "InfraredLight", "Scan", "Path", "GoPos", "RowCol", "CircSameAngle", "CircSameArcLen", "SpiralLine" };
        public static Dictionary<string, string> ChineseToEnglishDic(Dictionary<string, string> dictRecipeItem)
        {
            Dictionary<string, string> dictRecipeItemTemp = new Dictionary<string, string>(dictRecipeItem);
            foreach (var item in dictRecipeItem)
            {
                for (int i = 0; i < chinese.Length; i++)
                {
                    if (item.Value.Contains(chinese[i]))
                    {
                        dictRecipeItemTemp[item.Key] = dictRecipeItem[item.Key].Replace(chinese[i], english[i]);
                    }
                }
            }
            return dictRecipeItemTemp;
        }
        public static Dictionary<string, string> EnglishToChineseDic(Dictionary<string, string> dictRecipeItem)
        {
            Dictionary<string, string> dictRecipeItemTemp = new Dictionary<string, string>(dictRecipeItem);
            foreach (var item in dictRecipeItem)
            {
                for (int i = 0; i < english.Length; i++)
                {
                    if (item.Value.Contains(english[i]))
                    {
                        dictRecipeItemTemp[item.Key] = dictRecipeItem[item.Key].Replace(english[i], chinese[i]);
                    }
                }
            }
            return dictRecipeItemTemp;
        }


        public static List<string> GetWafersID(string strPortName)
        {
            PortInfo portInfo = null;
            if (strPortName == "Port_1")
            {
                portInfo = ParameterHelper.PortA;
            }
            else if (strPortName == "Port_2")
            {
                portInfo = ParameterHelper.PortB;
            }
            return portInfo.MapDatas.Select(n => n.WaferID).ToList() ?? null;
        }

        private static void SeLogMsg(string strLogMsg)
        {
            LogHelper.Write(LogHelper.Module.Procedure, $"SECS: {strLogMsg}");
        }
    }
}
